package com.lancoo.znbkxx.teacher.aibkTestCoach.paperToPersonalAnalysis.aibkAnalysisZW

import com.lancoo.znbkxx.teacher.aibkTestCoach.paperToPersonalAnalysis.AnalysisInforIndexHelp.getChildListBean
import android.text.Html
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.aibkTools.LancooMethod
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseFragment
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.PaperPerAnalysisInfor
import com.lancoo.znbkxx.teacher.utils.WebStyleUtils
import com.lancoo.znbkxx.teacher.widget.CustomTextViewToPicture
import kotlinx.android.synthetic.main.aibk_adapter_item_itemanalysis.view.*
import kotlinx.android.synthetic.main.aibk_adapter_item_itemanswer_zw.view.*
import kotlinx.android.synthetic.main.aibk_adapter_item_itemscore.view.*
import kotlinx.android.synthetic.main.aibk_adapter_item_word_stuanswer_zw.view.*
import kotlinx.android.synthetic.main.aibk_fragment_child_zw_analysis_word.view.TvQuesNumber
import kotlinx.android.synthetic.main.aibk_include_layout_zw_comment.view.*

class AnalysisChildFargmentWord(
        val activity:AppCompatActivity,
        val paperPerAnalysisInfor: PaperPerAnalysisInfor,
        val index_A:Int,
        val index_B:Int,
        val index_C:Int
) : KBaseFragment() {

    private var rootView: View? = null

    override fun createLayout(): Int {
        return R.layout.aibk_fragment_child_zw_analysis_word
    }

    override fun initView(view: View?) {
        rootView = view

        //显示序号
        val itemSortIndex = getChildListBean(paperPerAnalysisInfor, index_A, index_B, index_C).ItemList[0].ItemSortIndex
        rootView!!.TvQuesNumber.text = "$itemSortIndex. "

        //显示作答得分
        val comment = paperPerAnalysisInfor.TypeList[index_A].QuesAnswerList[index_B].Comment
        val evalScore = paperPerAnalysisInfor.TypeList[index_A].QuesAnswerList[index_B].ChildAnswerList[0].ItemList[0].EvalScore
        val scoreRate = paperPerAnalysisInfor.TypeList[index_A].QuesAnswerList[index_B].ChildAnswerList[0].ScoreRate
        val state = paperPerAnalysisInfor.TypeList[index_A].QuesAnswerList[index_B].ChildAnswerList[0].State
        if(state == 0){
            rootView!!.TvItemScoreTitle.setTextColor(activity.resources.getColor(R.color.lancoooBlue));
            rootView!!.TvItemScore.setTextColor(activity.resources.getColor(R.color.lancoooBlue));
            rootView!!.TvItemScore.text = "--"
        }else{
            if(scoreRate>=0.6){
                rootView!!.TvItemScoreTitle.setTextColor(activity.resources.getColor(R.color.lancoooGreen));
                rootView!!.TvItemScore.setTextColor(activity.resources.getColor(R.color.lancoooGreen));
            }else{
                rootView!!.TvItemScoreTitle.setTextColor(activity.resources.getColor(R.color.lancoooRed));
                rootView!!.TvItemScore.setTextColor(activity.resources.getColor(R.color.lancoooRed));
            }
            rootView!!.TvItemScore.text = evalScore+"分"
        }

        //显示学生作答
        var stuAnswer = paperPerAnalysisInfor.TypeList[index_A].QuesAnswerList[index_B].ChildAnswerList[0].StuAnswer
        if (stuAnswer.isEmpty()) {
            stuAnswer = "未填写"
        }
        rootView!!.TvWordTxt.text = stuAnswer
        //显示作答字符数
        var textInputWordCount = LancooMethod.getKeyCount(stuAnswer!!.trim(), " ") + 1
        if (stuAnswer!!.trim().isEmpty() || stuAnswer == "未填写") {
            rootView!!.TvStuWordCount.visibility = View.GONE
        } else {
            rootView!!.TvStuWordCount.visibility = View.VISIBLE
            rootView!!.TvStuWordCount.text = Html.fromHtml(
                    activity.resources.getString(R.string.aibk_zw_word_count_blue, textInputWordCount)
            )
        }

        //显示大数据评阅评语
        if(comment.isEmpty()){
            rootView!!.LlItemComment.visibility = View.GONE
        }else{
            rootView!!.LlItemComment.visibility = View.VISIBLE
            rootView!!.TvItemComment.text = comment
        }


        //显示参考范文
        var childAnswer = getChildListBean(paperPerAnalysisInfor, index_A, index_B, index_C).ChildAnswer
        WebStyleUtils.showWebViewCssStyle(activity, rootView!!.WvItemAnswer, childAnswer, false)

        //显示答案解析
        var childAnalysis = getChildListBean(paperPerAnalysisInfor, index_A, index_B, index_C).ChildAnalysis
        if (childAnalysis.isEmpty()) {
            childAnalysis = activity.getString(R.string.aibk_no_text) //...略
        }
        CustomTextViewToPicture(activity, rootView!!.TvItemAnalysis, childAnalysis)
    }

}